package com.iweb.day10;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * @author WuYongheng
 * @date 2021/11/20
 * @desc 模块文件备份操作
 */
public class Test2 {
    public static void main(String[] args) {
        String path1 = "d:\\a.txt";
        String path2 = "d:\\b.txt";
        InputStream inputStream = null;
        OutputStream outputStream = null;
        try {
            // 判断对象是否存在
            inputStream = new FileInputStream(path1);
            outputStream = new FileOutputStream(path2, true);
            // 进行读写操作
            // 设置缓冲区数组 ,每次读5个字节
            byte[] dates = new byte[5];
            int read = -1;
            while (true) {
                // 读操作
                read = inputStream.read(dates);
                if (read == -1) {
                    break;
                }
                // 写操作,追加
                outputStream.write(dates);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
